package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/10/24 22:18
 * @description：
 */
public class 子集 {
    @Test
    public void test() {
        Solution solution = new Solution();
        List<List<Integer>> subsets = solution.subsets(new int[]{1, 2, 3});
        for (int i = 0; i < subsets.size(); i++) {
            System.out.println(subsets.get(i));
        }
    }


    class Solution {
        List<List<Integer>> ans = new ArrayList<>();
        List<Integer> t = new ArrayList<>();
        public List<List<Integer>> subsets(int[] nums) {
            int n =  nums.length;
            for (int mask = 0; mask < (1 << n); mask++) {
                t.clear();
                for (int i = 0; i < n; i++) {
                    if ((mask & (1 << i)) != 0) {
                        t.add(nums[i]);
                    }
                }
                ans.add(new ArrayList<>(t));
            }
            return ans;
        }
    }
}
